<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加订单-后台管理系统-Admin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/weadmin.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/treeselect.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <%--<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/treeselect.js" charset="utf-8"></script>--%>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="weadmin-body">
    <form class="layui-form"   lay-filter="pushform">
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="we-red">*</span>商品类别
            </label>
            <div class="layui-input-inline">
                <select name="cid" id="op1">
                    <option value="1" id="op2" >手机数码</option>
                    <option value="2" id="op3">电脑办公</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="pname" class="layui-form-label">
                <span class="we-red">*</span>商品标题
            </label>
            <div class="layui-input-inline">
                <input type="text" id="pname" name="pname" required="" lay-verify="required" autocomplete="off"
                       class="layui-input"  value=""/>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="marketPrice" class="layui-form-label">
                <span class="we-red">*</span>商品价格
            </label>
            <div class="layui-input-inline">
                <input type="text" id="marketPrice" name="marketPrice" required="" lay-verify="number" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item ">
            <label  class="layui-form-label">  <span class="we-red">*</span>描述</label>
            <div  class="layui-input-inline">
                <%--第一步--%>
                <textarea   id="pdesc" name="pdesc" class="layui-textarea"    ></textarea>
            </div>
            <input type="hidden" name="pid"  id="hpid" value="<%=request.getParameter("pid")%>"/>
        </div>



        <div class="layui-form-item">
            <label for="add" class="layui-form-label">
            </label>
            <button id="add" class="layui-btn" lay-filter="add" lay-submit="">增加/编辑</button>
        </div>
    </form>
</div>
<script>
/*
    layui.extend({
        admin: '${pageContext.request.contextPath}/static/js/admin',
        treeselect: '${pageContext.request.contextPath}/static/js/treeselect'
    });
*/





    layui.use(['form', 'admin','layer', 'layedit', 'treeselect','jquery'], function () {
        var form = layui.form,
            admin = layui.admin,
            layer = layui.layer,
            layedit = layui.layedit,
           /* treeselect = layui.treeselect,*/
            $=layui.jquery;



        function  formrender(){
            form.render();

        }

        $(function () {
            $.ajax({
                url:"../../item/edit2",
                data:{"pid":$("#hpid").val()},
                dataType:"json",
                type:"post",
                success:function(d){
                    if(d!= null){

                        if(d.cid==1){
                            /*document.getElementById("op1").getElementsByTagName("option")[0].selected = true;*/

                            $("#op2").attr("selected",true);
                            formrender();
                        }else {
                            /*document.getElementById("op1").getElementsByTagName("option")[1].selected = true;*/
                            $("#op3").attr("selected",true);
                            formrender();
                        }

                       $("#pname").val(d.pname);
                        $("#marketPrice").val(d.marketPrice);

                        $("#pdesc").val(d.pdesc);

                    }else{


                    }
            }
            });
        });


        //初始化树形下拉框
       /* treeselect.render(
            {
                elem: "#cid",
                data: [{ //节点
                    name: '父节点1',
                    spread: false
                    ,children: [{
                        name: '子节点11'
                    },{
                        name: '子节点12'
                    }]
        },{
                name:'父节点2',
                    spread:false
                    ,children:[{
                    name: '子节点21'
                }]
            }],
            method: "GET"
        });*/

        //第二步
        //初始化富文本编辑器
        /*layedit.build('pdesc', {
            height: 55,//设置编辑器高度

        });*/

        //监听提交
        form.on('submit(add)', function (data) {
            alert("提交成功")
            $.ajax({
                url:"../../item/update",
                data:{},
                dataType:"json",
                type:"post",
                success:function(d){


                    }

                })
        });

    });
</script>
</body>

</html>